Git Kata 7: Collaboration as Ken
Learn about two contributors pushing commits to a shared repository.
We'll cover the following
This kata is all about two contributors pushing commits to a shared repository. Given that there’s only one of you, you’ll have to do a little role-playing. Starting with this kata, you’ll be playing the part of Ken and Carrie Coder.
First, we’ll clone the web-storelist repository as Ken, then again as Carrie. We’ll then switch back and forth between Ken and Carrie’s local repositories, making commits and pushing them to the Gogs server. We’ll also see how to get commits from a remote repository while updating a local repository.
Open two terminals using the plus (+) sign:
1 of 2
2 of 2
Step 1: Clone and configure the repository#
In the Ken window below is the command to clone the repository:
Commands
Command / Parameter | Description |
| This changes to the |
| The The first parameter is This is the URL to the remote repository. The second parameter is This is the directory in which to initialize and download the remote. If the directory doesn't exist, it will be created. |
This step uses the git clone command to retrieve a repository from a remote repository (the Gogs repository). The repository we cloned is the same one we pushed to the Gogs server in the previous kata.
The entire repository is downloaded from the remote, including the working directory and the index, which includes the entire history of the repository. This is now Ken’s local repository. Ken can make changes in his local repository and push them to the Gogs server. We’ll make commits to this repository as Ken.
The output of this command is:
Output
Message | Meaning |
"Cloning into ‘ken.coder’..." | Git is cloning the |
"remote: Counting objects: 5, done" "remote: Finding sources: 100% (5/5)" "remote: Getting sizes: 100% (4/4)" "remote: Total 5 (delta 0), reused 5 (delta 0)" "Unpacking objects: 100% (5/5), done." | This is a summary of the actions Git takes to download the repository. |
The command to change the directory and list all the files is given below:
Commands
Command / Parameter | Description |
| This changes to Ken's new local repository directory. |
| This lists all the files and directories, including the hidden ones. |
The working directory includes the three files committed to the Gogs server and the .git hidden folder where the index and other Git objects are stored.
The command to configure the repository is given below.
Command's Parameters
Command / Parameter | Description |
| This sets the configuration values for the Git repository. |
| This sets the username and email address of the local repository. |
| This saves the remote repository password in a local configuration store. This is for convenience and shouldn’t be used in a production scenario. |
The identity of the local user must be set before commits can be made to the local repository.
The configuration credential.helper store is used to save the remote repository password locally, so we don’t have to enter it each time we commit. This is for convenience and isn’t a best practice. Best-practice options for authentication with production Git servers include directory-based (LDAP) authentication and/or SSH keys.
In the Carrie window below is the command to clone the repository:
This is a repeat of the previous step. We clone the web-storelist repository again, this time to Carrie’s local repository. We’ll make commits to this repository as Carrie.
The command to change the directory and list all the files is given below.
Command
Command / Parameter | Description |
| This lists all the files and directories, including the hidden ones. |
Carrie’s local repository is now identical in content to Ken’s local repository.
The command to configure the repository is given below.
Command's Parameters
Command / Parameter | Description |
| This sets configuration values for the Git repository. |
| This sets the username and email address of the local repository. |
| This saves the remote repository password in a local configuration store. This is for convenience and shouldn't be used in a production scenario. |
Carrie’s local repository is now configured with her username and email address.
Step 2: Make changes as Ken and push#
In the Ken window below is the command to open a file in the text editor.
This command opens the storelist.htm file in the text editor.
To change and save the file:
- Replace “Enter list here…” with the first three items from the Main List.
- Save the file.
1 of 2
2 of 2
The coders have run out of milk, yogurt, and paper towels. Ken adds those items from the Main List to the Next Visit list. We can refresh the page to see the items added.
The command to display the status of the repository is given below.
Command's Parameter
Command / Parameter | Description |
| This displays the status of the files in the working directory of the repository. |
The git status command shows that the storelist.htm file has been modified.
The output of this command is:
Output
Message | Meaning |
"On branch master" | This is the current branch. |
"Initial commit" | No commits have been made, so the next commit will be the initial (first) commit. |
"Your branch is up-to-date with ‘origin-master’" | There have been no commits to the local branch since it was synchronized with the remote repository (the Gogs server). |
"Changes not staged for commit: (use “git add <file>…” to update what will be committed)" | The list below this message includes all the files that have been modified since the last commit. |
"modified: storelist.txt" | This is the only file in the working directory listed as untracked. |
"nothing added to commit but untracked files present (use “git add” to track)" | There are no changes to be committed, but Git reminds us that there are untracked files in the working directory. |
The command to commit the changes is given below.
Command's Parameters
Command / Parameter | Description |
| This creats a new commit in the repository. |
| This stages all the modified files to the index prior to creating the commit. |
| The |
| This is the commit message. It must be enclosed in quotes. |
Ken has committed his changes to storelist.htm.
The output of this command is:
Output
Message | Meaning |
"[master 8f55834] Adding items" | This is the branch, hash, and commit message of the commit. |
"1 file changed, 6 insertions(+), 2 deletions (-)" | This is a summary of the changes included in the commit. |
The command to push the commits is given below.
Enter “katas” for the password.
Command's Parameters
Command / Parameter | Description |
| This sends commits on the designated branch to a remote repository. |
| The |
| This is the name of the remote to which the pushed commits will be sent. |
| This is the name of the local branch from which the commits are sent. |
Ken uses git push to send his commits to the remote repository.
The output of this command is:
Output
Message | Meaning |
"Counting objects: 100% (5/5), done." | Git counts the number of objects (files) to be sent to the remote repository. |
"Compressing objects: 100% (3/3), done." | Git uses compression prior to sending them to the remote to make storage and transmission more efficient. |
"Writing objects: 100% (3/3), 333 bytes 333.00 KiB/s, done" | Git writes the objects to the remote. |
"Total 3 (delta 1), reused 0 (delta 0)" | This is a summary of the files sent. |
"To https://ed-6091404232622080.educative.run:3000/devops/web-storelist" | This is the URL of the remote to which the commits were sent. |
"2da83fa..c7601c5 master -> master" | This is the hashes of the ref updated in the local and remote repositories. |
"Branch 'master' set up to track remote branch" 'master' I from 'origin'" | A tracking branch has been created to track differences between |
Git Kata 6: Remote Repositories
Git Kata 7: Collaboration as Carrie